package com.jspgou.cms.entity;

import java.util.Date;
import java.util.HashSet;
import java.util.Set;

import com.jspgou.cms.entity.base.BaseShopMember;

public class ShopMember extends BaseShopMember {
	private static final long serialVersionUID = 1L;
	   
	/* [CONSTRUCTOR MARKER BEGIN] */
	public ShopMember () {
		super();
	}

	/**
	 * Constructor for primary key
	 */
	public ShopMember (java.lang.Long id) {
		super(id);
	}

	/**
	 * Constructor for required fields
	 */
	public ShopMember (
		java.lang.Long id,
		com.jspgou.core.entity.Website website,
		com.jspgou.cms.entity.ShopMemberGroup group,
		java.lang.Integer score,
		java.lang.Integer frrzeScore) {

		super (
			id,
			website,
			group,
			score,
			frrzeScore);
	}

	/**
	 * 添加到店铺中
	 * 
	 * @param tag
	 */
	public void addToStores(Store store) {
		Set<Store> set =getStores();
		if (set == null) {
			set = new HashSet<Store>();
			setStores(set);
		}
		set.add(store);
	}
	
	/**
	 * 添加至角色
	 * 
	 * @param tag
	 */
	public void addToRoles(Role role) {
		Set<Role> set =getRoles();
		if (set == null) {
			set = new HashSet<Role>();
			setRoles(set);
		}
		set.add(role);
	}
	
	public void init() {
		if (getScore() == null) {
			setScore(0);
		}
		if(getIsEmployee()==null){
			setIsEmployee(false);
		}
	}

	public Date getCreateTime() {
		return getMember().getCreateTime();
	}

	public Boolean getDisabled() {
		return getMember().getDisabled();
	}

	public String getUsername() {
		return getMember().getUsername();
	}

	public String getEmail() {
		return getMember().getEmail();
	}

	public String getPassword() {
		return getMember().getPassword();
	}

	public Long getLoginCount() {
		return getMember().getLoginCount();
	}

	public String getRegisterIp() {
		return getMember().getRegisterIp();
	}

	public java.util.Date getLastLoginTime() {
		return getMember().getLastLoginTime();
	}

	public String getLastLoginIp() {
		return getMember().getLastLoginIp();
	}

	public Date getCurrentLoginTime() {
		return getMember().getCurrentLoginTime();
	}

	public String getCurrentLoginIp() {
		return getMember().getCurrentLoginIp();
	}
	
	public Set<String> getPerms() {
		Set<Role> roles = getRoles();
		if (roles == null) {
			return null;
		}
		Set<String> allPerms = new HashSet<String>();
		for (Role role : getRoles()) {
			allPerms.addAll(role.getPerms());
		}
		return allPerms;
	}
	
	public boolean isSuper() {
		Set<Role> roles = getRoles();
		if (roles == null) {
			return false;
		}
		for (Role role : getRoles()) {
			if (role.getSuper()) {
				return true;
			}
		}
		return false;
	}
}